package org.example.core.web;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 返回结果
 * @author Calvin
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(name = "状态码")
    private Integer code;

    @Schema(name = "状态信息")
    private String message;

    @Schema(name = "返回数据")
    private T data;

    @Schema(name = "错误信息")
    private String error;

    public Result() {
    }

    public Result(Integer code) {
        this(code, null);
    }

    public Result(Integer code, String message) {
        this(code, message, null);
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.error = null;
    }

    public Result(Integer code, String message, T data, String error) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.error = error;
    }
}
